package com.lori.order.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lori.netshop.util.NetshopResult;
import com.lori.order.pojo.Order;
import com.lori.order.service.OrderService;

/**
 * 订单控制器
 * @author Administrator
 *
 */
@Controller
public class OrderController {
	@Autowired
	private OrderService orderServiceimp;
	
	/**
	 * 创建订单
	 * @param order
	 * @return
	 */
	@RequestMapping("/create")
	@ResponseBody
	public NetshopResult createOrder(@RequestBody Order order){
		try {
			NetshopResult create = orderServiceimp.create(order);
			return create;
		} catch (Exception e) {
			e.printStackTrace();
			return NetshopResult.build(500, e.toString());
		}
	}
	/**
	 * 获得订单数据
	 */
	@RequestMapping("/orders/{userId}")
	@ResponseBody
	public NetshopResult getOrders(@PathVariable long userId){
		System.out.println(userId);
		NetshopResult order = orderServiceimp.getOrder(userId);
		return order;
	}
}
